<script lang="tsx">
/**
 * 博客全局配置
 */

export default {
  name: "blog-global-config"
}
</script>

<script lang="tsx" setup>

import {ref} from "vue";
import {convertEnumToList, definePageModel, PageModel} from "@/framework";
import APIS from "@/apis";
import {GlobalConfigEnum} from "@/pages/blog/blog-global-config/index.ts";


/**
 * 页面模型
 */
const pageModelRef = ref()
const config = definePageModel<any>({
  url: APIS.BLOG_GLOBAL_CONFIG_BASE,
  getImmediate: true,
  searchForm: {
    beforeSubmit(data) {
      if (data.endTime) {
        data.endTime += " 23:59:59"
      }
      return data
    },
    els: [
      {
        eType: "el-input",
        prop: "code",
        props: {
          placeholder: "全局配置编码",
          clearable: true
        }
      },
      {
        eType: "el-select",
        prop: "status",
        props: {
          placeholder: "全局配置类型",
          clearable: true
        },
        optionsData: {
          list: convertEnumToList(GlobalConfigEnum),
          label: "label",
          value: "value"
        }
      },
      {
        eType: "el-input",
        prop: "content",
        props: {
          placeholder: "全局配置内容",
          clearable: true
        }
      },
      {
        eType: "el-date-picker",
        prop: "startTime",
        props: {
          valueFormat: "YYYY-MM-DD",
          placeholder: "创建时间-起始",
          clearable: true
        }
      },
      {
        eType: "el-date-picker",
        prop: "endTime",
        props: {
          valueFormat: "YYYY-MM-DD",
          placeholder: "创建时间-结束",
          clearable: true
        }
      },
    ]
  },
  programForm: {
    els: [
      {
        label: "新增",
        eType: "el-button",
        props: {
          type: "primary"
        },
        event: "add"
      },
    ]
  },
  table: {
    selection: true,
    page: {
      enable: true,
      pageSize: 20
    },
    operation: {
      width: 100,
      els: [
        {
          eType: "el-button",
          label: "编辑",
          event: "edit",
          props: {
            type: "primary",
            link: true
          }
        },
        {
          eType: "el-button",
          label: "删除",
          event: "delete",
          props: {
            type: "primary",
            link: true
          }
        }
      ]
    },
    props: {
      stripe: true,
      border: true
    },
    els: [
      {
        label: "全局配置编码",
        prop: "code",
        minWidth: 100
      },
      {
        label: "全局配置类型",
        prop: "status",
        minWidth: 120,
        renderFn(data) {
          return <span>{GlobalConfigEnum[data.status]}</span>
        },
      },
      {
        label: "全局配置内容",
        prop: "content",
        minWidth: 160
      },
      {
        label: "创建时间",
        prop: "createTime",
        minWidth: 200,
        renderFn(data) {
          return <span>{data.createTime?.split(' ')[0]}</span>
        },
      },
    ]
  },
  form: {
    title: "新增/编辑",
    width: 500,
    sheetForm: {
      labelWidth: "120px",
      required: ['code', 'content', 'status'],
      els: [
        {
          label: "全局配置编码",
          prop: "code",
          eType: "el-input",
          props: {
            placeholder: "全局配置编码",
            clearable: true
          }
        },
        {
          label: "全局配置内容",
          prop: "content",
          eType: "el-input",
          props: {
            placeholder: "全局配置内容",
            clearable: true
          }
        },
        {
          label: "全局配置类型",
          prop: "status",
          eType: "el-select",
          props: {
            placeholder: "全局配置类型",
            clearable: true
          },
          optionsData: {
            list: convertEnumToList(GlobalConfigEnum),
            label: "label",
            value: "value"
          }
        },
      ]
    }
  }
})

/**
 * 新增
 */
const handleAdd = () => {
  pageModelRef.value.handleAdd()
}

/**
 * 编辑
 */
const handleEdit = (row: any) => {
  pageModelRef.value.handleEdit(row)
}

/**
 * 删除
 */
const handleDelete = (row: any) => {
  pageModelRef.value.handleDelete(row)
}

</script>

<template>
  <PageModel ref="pageModelRef" :PageModel="config" @add="handleAdd" @delete="handleDelete" @edit="handleEdit"/>
</template>

<style lang="scss" scoped>

</style>